<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<title>参数字典明细维护</title>
		
		<link rel="stylesheet" type="text/css" href="../css/cm-default.css"  />
		<link rel="stylesheet" type="text/css" href="../ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link rel="stylesheet" type="text/css" href="../ligerUI/skins/ligerui-icons.css" />
		<script src="../js/jquery-min.js" type="text/javascript"></script>
		<script src="../js/validate/jquery.validate.js" type="text/javascript"></script>
		<script src="../js/validate/jquery.metadata.js" type="text/javascript"></script>
		<script src="../js/validate/messages_zh.js" type="text/javascript"></script>
		<script src="../ligerUI/js/ligerui.min.js" type="text/javascript"></script>
		<script src="../js/common.js" type="text/javascript"></script>
		<script type="text/javascript">
			var defGrid;
			var refid;
			$(function(){
				refid=window.location.toString().replace(/^[^?]+\?defid=/,'');
				$("#layout_main").ligerLayout({
                });

               	defGrid = $("#query_list").ligerGrid({
                    columns:[
						{display:'操作',isSort:false,width:60,render:function(rowdata,rowindex,value) {
                        	var h = "";
                        	if (!rowdata._editing) {
                                h += "<a href='javascript:void(0);' class='opt-link' onclick='beginEdit(" + rowindex + ")'>修改</a> ";
                                h += "<a href='javascript:void(0);' class='opt-link' onclick='deleteRow(" + rowindex + ")'>删除</a> "; 
                            } else {
                                h += "<a href='javascript:void(0);' class='opt-link' onclick='endEdit(" + rowindex + ")'>提交</a> ";
                                h += "<a href='javascript:void(0);' class='opt-link' onclick='cancelEdit(" + rowindex + ")'>取消</a> "; 
                            }
                            return h;
                        },frozen:true},
                        {display:'数据项编号',name:'code',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                        {display:'所属参数字典',name:'dict_def_id',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                        {display:'上层数据项',name:'higher_id',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                        {display:'数据项名称',name:'name',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                        {display:'数据项值',name:'value',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                        {display:'显示顺序',name:'seq',width:80,minWidth:60,align:'left',editor:{type:'text'}},
                        {display:'分级码',name:'path',width:80,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'级数',name:'layer',width:100,minWidth:60,align:'left',editor:{type:'text'}},
	                   // {display:'明细否',name:'detail',width:80,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'明细否',name:'detail',width:70,data:getyesOrno,render:switcher_yesOrNo,editor:{type:'select',data:getyesOrno,textField:'name',valueField:'value',selectBoxHeight:50}},
	                    {display:'状态',name:'status',width:70,data:status,render:switcher,editor:{type:'select',data:getStatus,textField:'name',valueField:'value',selectBoxHeight:50}},
			            {display:'说明',name:'description',width:200,align:'left',editor:{type:'text'}}
                    ],
                    pageSize:10,
                    usePager: true,
                    sortName:'id',
                    width:'100%',
                    height:'100%',
                    dataAction:'server',
                    checkbox:false,
                    rownumbers:false,
                    fixedCellHeight:false,
                    colDraggable:true,
                    enabledEdit:true,
                    clickToEdit:false,
                    onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
//                     onUnSelectRow:unselected,
                    onReload: toQuery,
//                     onToFirst: toFirst,
//                     onToLast: toLast,
//                     onToNext: toNext,
//                     onToPrev: toPrev,
					  url: '../common/q.jsp', 
					  //wws 2014-2-23 增加分页信息 start
					  onToFirst: function(item) {
					      toQuery(item, 1);
					  },
					  onToLast: function(item) {
							var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
							if (defGrid.options.total % defGrid.options.pageSize > 0)
								p += 1;
							toQuery(item, p);
					  },
					  onToPrev: function(item) {
							var p = parseInt(defGrid.options.page);
							if (p > 1)
								p -= 1;
							else
								return;
							toQuery(item, p);
					  },
					  onToNext: function(item) {
					  	var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
							if (defGrid.options.total % defGrid.options.pageSize > 0)
								p += 1;
							var cp = parseInt(defGrid.options.page); 
							if (cp < p)
								cp += 1;
							toQuery(item, cp);
					  },
					  //wws 2014-2-23 增加分页信息 end 

                    param_status:'rbac.status',
                    param_yesOrNo:'yesOrNo'
				});
				defGrid.options.dataAction = 'server';
				appendAddBtn(openUserDef, "添加用户");
	            $("#newStatuNameS").ligerComboBox({
                    autocomplete: true,
                    valueField:'value',
                    textField:'name',
                    data:getStatus,
                    onSelected:function(v,t) {
                        $("#newStatus").val(v);
                    }
                });
				$("#pageloading").hide();
				//默认查询数据设置
				toQuery();
			});
	        function beginEdit(rowid) { 
	        	defGrid.beginEdit(rowid);
	        }
	        function cancelEdit(rowid) { 
	        	defGrid.cancelEdit(rowid);
	        }
	        function endEdit(rowid) {
	            defGrid.endEdit(rowid);
	            var row = defGrid.getRow(rowid);
	            toModify(JSON.stringify(row));
	        }
	        function deleteRow(rowid) {
	            $.ligerDialog.confirm('您确定要删除该项数据吗？', function(r) {
		            if (!r)
			            return;
	                var row = defGrid.getRow(rowid);
	                if (row['__status'] !== 'add')
	                	toDel(JSON.stringify(row));
	                defGrid.deleteRow(rowid);
	            })
	        }
			function switcher(item) {
				return paramRender(item, defGrid.options.param_status, item.status);
			}
			var getStatus = new function () {
				return getData('rbac.status');
			}
			function switcher_yesOrNo(item) {
				return paramRender(item, defGrid.options.param_yesOrNo, item.detail);
			}
			var getyesOrno = new function () {
				return getData('yesOrNo');
			}
			function toQuery(item, page, pageSize) {
				if (!page)
					page = defGrid.options.page;
				if (!pageSize)
					pageSize = defGrid.options.pageSize;
				
				var param = new Object();
			    param.code=$("#defCode").val();
				param.name = $("#defName").val();
				//param.code = $("#dictCode").val();
				param.status = $("#dictStatus").val();
				param.dict_def_id=refid;
				var data = JSON.stringify(reqObj('q','rbac.select.dict.def.queryItem',JSON.stringify(param),'l',true,page,pageSize));
				ajaxSubmit("/cmwifi/rbac/cm.do?m=q", data, function(data) {
                    //wws 2014-2-23 增加分页信息 start 
					var d = data['data'].Rows;
					var ps = defGrid.options.pageSize, p = defGrid.options.page, t = parseInt(data['data'].Total);
					if (t > ps) {
						for (var i = 0; i < (p - 1) * ps; i++) {
							d.unshift(null);
						}
					}
					defGrid.data = data['data'];
					 //wws 2014-2-23 增加分页信息  end 
					defGrid.set({data: data['data']});
				});
			}
			function toFirst() {
				toQuery(null, 1);
			}
			function toLast() {
				var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
				if (defGrid.options.total % defGrid.options.pageSize > 0)
					p += 1;
				toQuery(null, p);
			}
			function toNext() {
				var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
				if (defGrid.options.total % defGrid.options.pageSize > 0)
					p += 1;
				if (defGrid.options.page == p)
					return;
				toQuery(null, defGrid.options.page + 1);
			}
			function toPrev() {
				if (defGrid.options.page == 1)
					return;
				toQuery(null, defGrid.options.page - 1);
			}
			//新增用户弹出窗口
			var addDialog;
			function openUserDef() {
				toReset('#new_user_def input,select,textarea');
				addDialog = $.ligerDialog.open({
					target:$("#new_user_def"),
					title:"新增字典数据",
					width:450,
					height:550
				});
			}
			function validate() {
				var valid = true;
				
				$('*[id$="S"],*[id$="S_txt"]').each(function(index, element) {
					
					if (!$(this).rules()) return;
					if (!$(element).valid()) {
						valid = false;
						return;
					}
				});
				if (!valid) return false;
				
				return true
			}
			// 新增保存处理
			function toAdd() {
				
				if (!validate())
				{
				return;
				}
				var param = new Object();
				param.code=$("#codeS").val();
				param.dict_def_id=refid;
				param.higher_id='0';
				param.name = $("#newNameS").val();
				param.val = $("#newVALUES").val();
				param.seq=$("#newSEQ").val();
				param.detail=$("#newDetail").val();
				param.layer=1;
				param.status = $("#newStatus").val();
				param.desc=$("#newDesc").val();
				var data = JSON.stringify(reqObj('a','rbac.add.dict.item.add',JSON.stringify(param)));
				
				ajaxSubmit("/cmwifi/rbac/cm.do?m=a", data, function(data) {
					if (data) {
						//alert(parseInt(data['status']));
						if (parseInt(data['status']) > 0) {
							$.ligerDialog.success('保存成功', '操作完成', function() {
							addDialog.hide();
							toQuery();
						});
						} else if (parseInt(data['status']) == -1) {
							$.ligerDialog.error('用户[' + $("#newName").val() + ']已存在<br>不能重复添加','错误');
						} else {
							$.ligerDialog.error('保存失败');
						}
					}
				});
			}
			
		   function toModify(row) {
				
				 var param = JSON.stringify(reqObj('u','rbac.update.dict.defitem.update',row));
					//alert(param);
					ajaxSubmit("/cmwifi/rbac/cm.do?m=u", param, function(data) {
						if (data) {
							if (parseInt(data['status']) > 0) {
								$.ligerDialog.success('保存成功');
							} else {
								$.ligerDialog.error('保存失败');
							}
						}
					});
			}
		   //删除时，判断此用户下是否已设置角色信息，删除时提示，将删除用户的角色设置信息
		   //确认删除时，将用户下的角色设置信息一并删除。
			function toDel(row) {
				 var param = JSON.stringify(reqObj('d','rbac.delete.dict.item.delete',row));
					ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
						if (data) {
							if (parseInt(data['status']) > 0) {
								$.ligerDialog.success('删除成功');
							} else {
								$.ligerDialog.error('删除失败');
							}
						}
					});
			}
                
			
	    </script>
		<style type="text/css">
			label{margin: 5px 20px 5px 15px;}
			.fields{height:35px;padding-top:5px;}
			.dict-info{width: 260px;padding: 10px;}
			.diff {margin:3px 0;}
			.lineD {width:99%;float:left;position:relative;overflow:hidden;margin:10px 0 2px 2px}
			.labelD {width:26%;position:relative;float:left;padding-top:3px;}
			.dplD {width:73%;position:relative;float:left;}
			.title{font-size:14px;font-weight:bold;background-position:left;padding-left:18px;}
		</style>
	</head>
	<body style="padding:0;">
		<div id="pageloading"></div>  
		<div id="layout_main">
			<div position="center" id="a_center" title="用户列表">
				<div id="query_cond" class="fields">
					<label>编号</label><input type="text" class="s-text txt-def" id="defCode" />
					<label>名称</label><input type="text" class="s-text txt-def" id="defName" />
					<label>状态</label><select id="dictStatus" param="rbac.status" first=""></select>
					<input type="button" value="查询" style="margin-left:25px;" onclick="toQuery();" />
					<input type="button" value="清空" onclick="toReset('#query_cond input,select,textarea');" />
				</div>
				<div id="query_list"></div>
			</div>
		</div>
		<div id="new_user_def" style="display:none;overflow:hidden;">
			<form name="basic-form" method="post" id="basic_form" class="liger-form" data-validate="{}">
			     <div class="lineD" style="margin-bottom:10px;">
                <span class="title l-icon-add">添加字典数据项</span>
            </div>
			<div class="lineD">
				<div class="labelD"><label>编号</label></div>
				<div class="dplD"><input type="text"  ltype="text" class="required s-text txt-def" id="codeS" /></div>
			</div>
			
			<div class="lineD">
				<div class="labelD"><label>名称</label></div>
				<div class="dplD"><input type="text"  ltype="text" class="required s-text txt-def" id="newNameS" /></div>
			</div>
			<div class="lineD">
				<div class="labelD"><label>数据项值</label></div>
				<div class="dplD"><input type="text"  ltype="text" class="required s-text txt-def" id="newVALUES" /></div>
			</div>
			
			<div class="lineD">
				<div class="labelD"><label>显示顺序</label></div>
			<div class="dplD">
			<input type="text" class="s-text txt-def" id="newSEQ" /></div>
			</div>
			<div class="lineD">
				  <div class="labelD"><label>明细否</label></div>
				<div class="dplD"><select class="txt-def" id="newDetail" param="yesOrNo" default="1" style="margin-right: 30px;"></select></div>
			</div>
		    <div class="lineD">
                <div class="labelD"><label>状态</label></div>
                <div class="dplD"><input type="text" id="newStatuNameS" ltype="combobox" class="required s-text txt-def" /></div>
                <input type="hidden" id="newStatus" />
             </div>
			<div class="lineD">
				<div class="labelD"><label>说明</label></div>
				<div class="dplD"><textarea cols="24" rows="2" id="newDesc"></textarea></div>
			</div>
			<div class="lineD" style="margin-top:15px;padding-left:30%;">
				<input type="button" value="保存" onclick="toAdd();" />
				<input type="button" value="清空" onclick="toReset('#new_user_def input,select,textarea')" />
			</div>
			</form>
		</div>
	</body>
</html>